package com.example.gameapplication.bullet;

import android.content.res.Resources;
import android.graphics.Canvas;
import android.util.Log;

import com.example.gameapplication.database.DataUtils;

import java.util.ArrayList;

public class WindmillSkill {
    Resources resources;
    ArrayList<WindmillBullet>windmillBullets;
    boolean isInit;
    //原本计划利用画板旋转画图
    public WindmillSkill(Resources resources) {
        this.resources=resources;
        init();
    }
    //初始化
    private void init() {
        isInit=false;
        if (windmillBullets==null){
            windmillBullets=new ArrayList<>();
            DataUtils.getExecutorService().execute(initrunnable);
        }
    }

    public void drawSelf(Canvas canvas){
        if (isInit){
            for (int i=0;i<windmillBullets.size();i++){
                windmillBullets.get(i).drawSelf(canvas);
            }
            DataUtils.runWindmillArrack();
        }
    }
    Runnable initrunnable=new Runnable() {
        @Override
        public void run() {
            for (int i=0;i<12;i++){
                WindmillBullet windmillBullet = new WindmillBullet(resources, DataUtils.getPaint());
                windmillBullet.setAngle(i*30);
                windmillBullet.setClockwise(false);//逆时针
                windmillBullets.add(windmillBullet);
            }

            isInit=true;
        }
    };

    public ArrayList<WindmillBullet> getWindmillBullets() {
        return windmillBullets;
    }

    public void setWindmillBullets(ArrayList<WindmillBullet> windmillBullets) {
        this.windmillBullets = windmillBullets;
    }
    public void dataDestroyed(){
        if (windmillBullets!=null)
            while (windmillBullets.size()>0){
                windmillBullets.get(0).dataDestroyed();
                windmillBullets.remove(0);
            }
        windmillBullets=null;
        isInit=false;
    }
}
